/**
 * Created with IntelliJ IDEA.
 * Description: 牛客网: BM91 反转字符串
 * <a href="https://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3?tpId=295&tqId=1024337&ru=/exam/company&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Fcompany">...</a>
 * User: DELL
 * Date: 2023-08-02
 * Time: 22:27
 */
public class Solution {
    /**
     * 解题思路:
     * 利用 stringBuffer 的 append 方法拼接出一个逆序的字符串返回即可
     * @param str
     * @return
     */
    public String solve (String str) {
        // 合法性检验
        if (str == null) {
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        int index = str.length()-1;
        while (index >= 0) {
            stringBuffer.append(str.charAt(index));
            index--;
        }
        return stringBuffer.toString();
    }
}
